<?php
/**
 * 后台管理员控制器
 * UserModel: LLw
 * Date: 2020-01-07
 * Time: 11:48
 */
namespace app\caidongweb\controller;
use app\caidongweb\model\AdminModel;
use app\caidongweb\model\AuthGroup;
use think\Db;
use think\Request;

/**
 * Class Admin
 * 总后台管理员类
 * @package app\caidongweb\controller
 */
class Admin extends BaseController
{
    protected $admin;
    protected $authGroup;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->admin = new AdminModel();
        $this->authGroup = new AuthGroup();
    }

    //后台用户管理
    public function index()
    {
        $list = $this->admin->getList();
        $groupList = $this->authGroup->getList('status != 0');
        $this->assign('groupList',$groupList);
        $this->assign('list',$list);
        $this->assign('username',input('username'));
        $this->assign('page',$list->render());
        $this->assign('times',time());
        return view();
    }
    //用户编辑
    public function edit()
    {
        if(input('post.')){
            $res = $this->admin->edit();
            return $res;
        }else{
            $data = $this->admin->getUserInfo(input('id'));
            $groupList = $this->authGroup->getList('status != 0');
            $this->assign('groupList',$groupList);
            $this->assign('data',$data);
            return $this->fetch();
        }
    }
    //添加用户
    public function add()
    {
        if(input('post.')){
            $res = $this->admin->add();
            return $res;
        }else{
            $groupList = $this->authGroup->getList('status != 0');
            $this->assign('groupList',$groupList);
            return $this->fetch();
        }
    }
    //批量删除
    public function delList()
    {
        $res = $this->admin->delList();
        return $res;
    }
    //编辑状态
    public function updateStatus()
    {
        $res = $this->admin->updateStatus();
        return $res;
    }
    //管理信息
    public function info()
    {
        if(input('post.')){
            $res = $this->admin->edit();
            return $res;
        }else{
            $id = session('usid');
            $find = $this->admin->getUserInfo($id);
            $this->assign('find',$find);
            return view();
        }
    }
}